<template>
  <div :class="className" :style="{height:height,width:width}"/>
</template>

<script>

import * as echarts from 'echarts'

export default {
  name: "thirteen",
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '1500px'
    },
    height: {
      type: String,
      default: '750px'
    }
  },
  data() {
    return {
      chart: null,
      chartTimer: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOptions()
    },

    setOptions() {
      this.chart.setOption({
        grid: {
          top: '20%',
          left: '5%',
          right: '5%',
          bottom: '8%',
          containLabel: true,
        },
        tooltip: {
          show: true,
          trigger: 'item',
          formatter: '{a} <br/><br/> {b} : {c}',
          extraCssText: 'width: 512px; height: 100px;font-size: 36px; font-family: Arial;font-weight: bold;',
          textStyle: {
            fontStyle: 'normal',
            fontWeight: 'normal',
            fontFamily: 'sans-serif',
            color: '#000',
            fontsize: 60
          }
        },
        legend: {
          data: ['总笔数', '成功', '失败'],
          top: '5%',
          textStyle: {
            color: '#747474',
          },
        },
        xAxis: {
          type: 'category',
          data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            show: true,
            textStyle: {
              color: '#393939', //X轴文字颜色
            },
          },
        },
        yAxis: [
          {
            type: 'value',
            name: '(次数)',
            nameTextStyle: {
              color: '#393939',
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: '#eeeeee',
              },
            },
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
            },
            axisLabel: {
              show: true,
              textStyle: {
                color: '#393939',
              },
            },
          },
          {
            type: 'value',
            gridIndex: 0,
            min: 50,
            max: 100,
            splitNumber: 8,
            splitLine: {
              show: false,
            },
            axisLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            axisLabel: {
              show: false,
            },
            splitArea: {
              show: false,
              areaStyle: {
                color: ['rgba(250,250,250,0.0)', 'rgba(250,250,250,0.05)'],
              },
            },
          },
        ],
        series: [
          {
            name: '总笔数',
            type: 'bar',
            barWidth: 15,
            stack: 'BB',
            // barGap: 10,
            itemStyle: {
              emphasis: {
                barBorderRadius: 0,
              },
              //颜色样式部分
              normal: {
                barBorderRadius: 10,
                color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                  {offset: 0, color: "#cbf800"},
                  {offset: 1, color: "rgba(4,248,228,0.75)"},
                ]),
              },
            },
            data: [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],
          },
          {
            name: '成功',
            type: 'bar',
            barWidth: 15,
            stack: 'BB',
            // barGap: 10,
            itemStyle: {
              emphasis: {
                barBorderRadius: 0,
              },
              //颜色样式部分
              normal: {
                barBorderRadius: 10,
                color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                  {offset: 0, color: "#cbf50a"},
                  {offset: 1, color: "rgb(249,200,4)"},
                ]),
              },
            },
            data: [280, 210, 180, 170, 150, 145, 160, 130, 120, 120, 120, 120],
          },
          {
            name: '失败',
            type: 'bar',
            barWidth: 15,
            stack: 'BB',
            itemStyle: {
              emphasis: {
                barBorderRadius: 0,
              },
              //颜色样式部分
              normal: {
                barBorderRadius: 10,
                color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                  {offset: 0, color: "#5bb822"},
                  {offset: 1, color: "#9ef552"},
                ]),
              },
            },
            data: [28, 21, 18, 17, 15, 14, 16, 13, 12, 12, 12, 12],
          }
        ],
      })
    }
  }
}
</script>

<style scoped>

</style>
